package dp;

/**
 * Created with IntelliJ IDEA.
 * Description: 746. 使用最小花费爬楼梯
 * User: Li_yizYa
 * Date: 2025/7/1
 * Time: 10:24
 */
public class Solution3 {
    /**
     * 第一步不支付费用，最后一步支付
     * @param cost
     * @return
     */
    public int minCostClimbingStairs1(int[] cost) {
        if (cost == null || cost.length <= 1) {
            return 0;
        }
        int[] dp = new int[cost.length + 1];
        dp[0] = 0;
        dp[1] = 0;
        for (int i = 2; i <= cost.length; i++) {
            dp[i] = Math.min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);
        }
        return dp[cost.length];
    }
    /**
     * 第一步支付费用
     * @param cost
     * @return
     */
    public int minCostClimbingStairs(int[] cost) {
        if (cost == null || cost.length <= 1) {
            return 0;
        }
        int[] dp = new int[cost.length];
        dp[0] = cost[0];
        dp[1] = cost[1];
        for (int i = 2; i < cost.length; i++) {
            dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];
        }
        return Math.min(dp[cost.length - 1], dp[cost.length - 2]);
    }
}
